<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .top {
        display: flex;
      }
      .btn1,
      .btn2 {
        width: 120px;
        height: 50px;
        border: 1px solid #000;
      }
      .content {
        width: 400px;
        height: 500px;
        border: 1px solid #000;
      }
      .active {
        color: red;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="top">
        <div
          class="btn1"
          :class="{ active: active === 1 }"
          v-on:click="active = 1"
        >
          奇数
        </div>
        <div
          class="btn2"
          :class="{ active: active === 0 }"
          v-on:click="active = 0"
        >
          偶数
        </div>
      </div>
      <div class="content">
        <!-- <ul v-if="active === 1">
          <li v-for="item in oddList" :key="item">{{ item }}</li>
        </ul>
        <ul v-else>
          <li v-for="item in evenList" :key="item">{{ item }}</li>
        </ul> -->
        <ul>
          <li v-for="item in resultList" :key="item">{{ item }}</li>
        </ul>
      </div>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            list: [1, 2, 3, 4, 5, 6, 7, 8],
            active: 1,
          };
        },
        computed: {
          // oddList() {
          //   return this.list.filter((item) => item % 2 === 1);
          // },
          // evenList() {
          //   const arr = this.list.filter((item) => item % 2 === 0);
          //   return arr;
          // },

          resultList() {
            return this.list.filter((item) => item % 2 === this.active);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
